package juc;

import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.LockSupport;
import java.util.concurrent.locks.ReentrantLock;

public class LockSupportDemo {

	public static void main(String args[]){
	    Thread a = new Thread(() -> {
			try {
				TimeUnit.SECONDS.sleep(2);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("外层");
			LockSupport.park();
			System.out.println("end");

		});
		a.start();
		new Thread(() -> {
			LockSupport.unpark(a);
			System.out.println("start");

		}).start();
	}
}

class Foo {
	private final Map<String, Thread> map = new ConcurrentHashMap<>();
	private AtomicInteger size = new AtomicInteger(0);

	public Foo() {
	}

	public void first(Runnable printFirst) throws InterruptedException {
		map.put("first", Thread.currentThread());
		while (map.size() != 3) {

		}
		// printFirst.run() outputs "first". Do not change or remove this line.
		printFirst.run();
		LockSupport.unpark(map.get("second"));
	}

	public void second(Runnable printSecond) throws InterruptedException {
		map.put("second", Thread.currentThread());
		LockSupport.park();
		// printSecond.run() outputs "second". Do not change or remove this line.
		printSecond.run();
		LockSupport.unpark(map.get("third"));
	}

	public void third(Runnable printThird) throws InterruptedException {
		map.put("third", Thread.currentThread());
		LockSupport.park();
		// printThird.run() outputs "third". Do not change or remove this line.
		printThird.run();
	}
}